﻿@model DHQGHN.PM2.ViewModels.MappingPTDTViewModel


<script type="text/javascript">
        @functions{
        public string GetAntiForgeryToken()
            {
                string cookieToken, formToken;
                AntiForgery.GetTokens(null, out cookieToken, out formToken);
                return cookieToken + "," + formToken;
            }
        }

    var count = 0;
    $('td.radbtn input[type=radio]').click(function () {
        $('input[type=radio][name=checkall]').attr("checked", false);
        //$('#td' + $(this).attr('id')).css("color", "white");
        //$('#td' + $(this).attr('id')).css("background-color", "#19A3A3");
        //$('td#ra' + $(this).attr('id') + ' input[type=radio]').attr("disabled", false);
        if ($('td#chkco' + $(this).attr('id') + ' input').val() == "0") {
            alert('Không có hộ nào trong địa bàn đã chọn');
            $('td.radbtn' + ' input[id="' + $(this).attr('id') + '"][value=""]').prop('checked', true);
            //$('#' + getchkid).prop('checked', false);
            //$('td#ra' + $(this).attr('id') + ' input[type=radio]').attr("disabled", true);
            //$('#td' + $(this).attr('id')).css("color", "black");
            //$('#td' + $(this).attr('id')).css("background-color", "white");
            event.preventdefault();
        }
    });

    $('#save').click(function () {

        var codeListVal = null;
        var methodListVal = null;
        codeListVal = [];
        methodListVal = [];
        $('td.radbtn input[type=radio]:checked').each(function () {
            if ($('input[name="me' + $(this).attr('id') + '"]:checked').attr('value') != '') {
                codeListVal.push($('input[name="me' + $(this).attr('id') + '"]:checked').attr('id'));
                methodListVal.push($('input[name="me' + $(this).attr('id') + '"]:checked').attr('value'));
            }
        });
        if (codeListVal.length != methodListVal.length) {
            alert('Yêu cầu chọn phương thức điều tra cho các địa bàn đã chọn');
            return false;
        }
        $('#AREA_ID').val(codeListVal);
        $('#SURVEY_METHOD_ID').val(methodListVal);
        if (codeListVal.length == 0) {
            return false;
        }
    });

    $('input[type=radio][name=checkall]').change(function () {
        var value = $(this).val();
        $('.radbtn').each(function () {
            if ($(this).closest('tr').children('td:eq(2)').find('input').val() != "0") {
                if (value == "02")
                    $('input[type=radio]', this).get(0).checked = true;
                else if (value == "03")
                    $('input[type=radio]', this).get(1).checked = true;
            }
        });
    });
</script>
<style>
    th, td {
        border: 1px solid #C0C0C0;
        padding: 3px;
    }

    input[type="radio"]:checked + label {
        background-color: #19A3A3;
        color: white;
    }
</style>

@using (Html.BeginForm("PhuongThucDTPost", "HouseHold", FormMethod.Post))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)
    @Html.HiddenFor(model => model.AREA_ID)
    @Html.HiddenFor(model => model.CODE)
    @Html.HiddenFor(model => model.SURVEY_METHOD_ID)
    <div class="row" align="center" style="padding-bottom:10px">
        <div class="col-md-12">
            @*@Html.Label("Phương thức điều tra: ") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                @Html.RadioButtonFor(model => model.SURVEY_METHOD_ID, "02", new { @checked = true, @class = "text-center" }) Điều tra Tablet &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                @Html.RadioButtonFor(model => model.SURVEY_METHOD_ID, "03") Điều tra Giấy &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <span>@Html.ValidationMessageFor(model => model.SURVEY_METHOD_ID)</span>*@
            <div style="font-style:italic; margin-bottom: 10px">*Chú ý: Các địa bàn "Có 0 hộ có thể gán" sẽ không được chọn phương thức điều tra</div>
            <button id="save" type="submit" class="btn btn-md" value="Lưu"><i class="fa fa-check"></i> Lưu</button>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            <table align="center" style="width:100%;">
                <thead>
                    <tr>
                        <th style="text-align:center">Tên địa bàn</th>
                        <th style="text-align:center">Thông tin</th>
                        <th style="text-align:center">
                            Phương thức điều tra đã chọn
                            <br />
                            <div>
                                <input type="radio" name="checkall" class="checkall" value="02"><label for="checkall">Tất cả Điều tra Tablet</label> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <input type="radio" name="checkall" class="checkall" value="03"><label for="checkall">Tất cả Điều tra Giấy</label>
                            </div>
                        </th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var adm in @Model.AdmUnitSelected)
                    {
                        var checkBoxSelected = "chk" + adm.AREA_ID;
                        var text = "td" + adm.AREA_ID;
                        var checkcount = "chkco" + adm.AREA_ID;
                        var alert = "al" + adm.AREA_ID;
                        var ptdt = "ptdt" + adm.AREA_ID;
                        var radio = "ra" + adm.AREA_ID;
                        var method = "me" + adm.AREA_ID;
                        <tr id="@adm.AREA_ID">
                            <td style="margin-left: 10px" width="30px" hidden="hidden">
                                <input type="text" hidden="hidden" id="@checkBoxSelected" name="mapped" class="mapped" value="@adm.AREA_ID" />
                            </td>
                            <td id="@text" style="padding: 0px 20px 0px 20px">
                                @adm.AREA_NAME
                            </td>
                            <td id="@checkcount" hidden="hidden">
                                <input type="text" value="@adm.RECODE_COUNT">
                            </td>
                            <td id="@alert" align="center" style="padding: 0px 20px 0px 20px">Có @adm.RECODE_COUNT hộ có thể gán</td>

                            @*@if (adm.SURVEY_METHOD_ID == "02")
                                {
                                    <td id="@ptdt" align="center" width="300px">Điều tra Tablet</td>
                                }
                                else if (adm.SURVEY_METHOD_ID == "03")
                                {
                                    <td id="@ptdt" align="center" width="300px">Điều tra Giấy</td>
                                }else
                                {
                                    <td id="@ptdt" align="center" width="300px">Chưa chọn phương thức điều tra</td>
                                }*@

                            @if (adm.SURVEY_METHOD_ID == "02")
                            {
                                <td id="@radio" class="radbtn" style="padding: 0px 0px 0px 30px" width="450px">
                                    <input type="radio" id="@adm.AREA_ID" name="@method" value="02" checked><label for="@adm.AREA_ID">Điều tra Tablet</label> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <input type="radio" id="@adm.AREA_ID" name="@method" value="03"><label for="@adm.AREA_ID">Điều tra Giấy</label> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <input type="radio" id="@adm.AREA_ID" name="@method" value=""><label for="@adm.AREA_ID">Chưa chọn PTĐT</label> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                </td>

                            }
                            else if (adm.SURVEY_METHOD_ID == "03")
                            {
                                <td id="@radio" class="radbtn" style="padding: 0px 0px 0px 30px" width="450px">
                                    <input type="radio" id="@adm.AREA_ID" name="@method" value="02"><label for="@adm.AREA_ID">Điều tra Tablet</label> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <input type="radio" id="@adm.AREA_ID" name="@method" value="03" checked><label for="@adm.AREA_ID">Điều tra Giấy</label> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <input type="radio" id="@adm.AREA_ID" name="@method" value=""><label for="@adm.AREA_ID">Chưa chọn PTĐT</label> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                </td>

                            }
                            else
                            {
                                <td id="@radio" class="radbtn" style="padding: 0px 0px 0px 30px" width="450px">
                                    <input type="radio" id="@adm.AREA_ID" name="@method" value="02"><label for="@adm.AREA_ID">Điều tra Tablet</label> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <input type="radio" id="@adm.AREA_ID" name="@method" value="03"><label for="@adm.AREA_ID">Điều tra Giấy</label> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <input type="radio" id="@adm.AREA_ID" name="@method" value="" checked><label for="@adm.AREA_ID">Chưa chọn PTĐT</label> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                </td>
                            }
                        </tr>
                    }
                </tbody>
            </table>
        </div>
    </div>
}
<br /><br />
